﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace KeywordAuction
{
    public class StrategyRaiseAll : StrategyBase
    {
        public override bool Action(Advertiser advertiser)
        {
            foreach (var item in advertiser.Biddings)
            {
                int index = item.AttendingAdspot.GetIndexAdvertiser(item);
                if (index != 0)
                {
                    var value = item.AttendingAdspot.Bitting.OrderByDescending(p => p.Bid).ToList()[index - 1].Bid;
                    item.Bid = value + 1;
                }
            }
            base.Action(advertiser);
            return true;
        }
    }
    public class StrategyDropAll : StrategyBase
   {
       public override bool Action(Advertiser advertiser)
       {
           base.Action(advertiser);
           foreach (var item in advertiser.Biddings)
           {
               var index = item.AttendingAdspot.GetIndexAdvertiser(item);
               if (index != item.AttendingAdspot.Bitting.Count -1)
               {
                   var value = item.AttendingAdspot.Bitting.OrderByDescending(p => p.Bid).ToList()[index + 1].Bid;
                   item.Bid = value -1;
               }


               //if (item.Bid - DropValue < 0)
               //{
               //    return false;
               //}
               //item.Bid -= DropValue;
           }
           return true;
       }
   }
   public class StrategyHoldAll : StrategyBase
   {
       public override bool Action(Advertiser advertiser)
       {
           base.Action(advertiser);
           return true;
       }

       public string Id
       {
           get;
           set;
       }
       public StrategyHoldAll()
       {
           Id = Guid.NewGuid().ToString();
       }
   }


    //Hard
   public class StrategyRaiseDrop : Simulation.Strategy.ValueStrategyBase
   {
       public override bool Action(Advertiser advertiser)
       {
           base.Action(advertiser);
           advertiser.Biddings.FirstOrDefault().Bid += RaiseValue;
           if (advertiser.Biddings.LastOrDefault().Bid - DropValue >= 0)
           {
               advertiser.Biddings.LastOrDefault().Bid -= DropValue;
           }
           else
           {
               return false;
           }
           return true;
       }
   }

   public class StrategyRaiseHold : Simulation.Strategy.ValueStrategyBase
   {
       public override bool Action(Advertiser advertiser)
       {
           advertiser.Biddings.FirstOrDefault().Bid += RaiseValue;
           base.Action(advertiser);
           return true;
       }
   }
   public class StrategyHoldRaise : Simulation.Strategy.ValueStrategyBase
   {
       public override bool Action(Advertiser advertiser)
       {
           advertiser.Biddings.LastOrDefault().Bid += RaiseValue;
           base.Action(advertiser);
           return true;
       }
   }
   public class StrategyDropRaise : Simulation.Strategy.ValueStrategyBase
   {
       public override bool Action(Advertiser advertiser)
       {
           base.Action(advertiser);
           if (advertiser.Biddings.FirstOrDefault().Bid - DropValue >= 0)
           {
               advertiser.Biddings.FirstOrDefault().Bid -= DropValue;
           }
           else
           {
               return false;
           }
           advertiser.Biddings.LastOrDefault().Bid += RaiseValue;
           return true;
       }
   }

   public class StrategyDropHold : Simulation.Strategy.ValueStrategyBase
   {
       public override bool Action(Advertiser advertiser)
       {
           base.Action(advertiser);
           if (advertiser.Biddings.FirstOrDefault().Bid - DropValue >= 0)
           {
               advertiser.Biddings.FirstOrDefault().Bid -= DropValue;
           }
           else
           {
               return false;
           }
           return true;
       }
   }

   public class StrategyHoldDrop : Simulation.Strategy.ValueStrategyBase
   {
       public override bool Action(Advertiser advertiser)
       {
           base.Action(advertiser);
           if (advertiser.Biddings.LastOrDefault().Bid - DropValue >= 0)
           {
               advertiser.Biddings.LastOrDefault().Bid -= DropValue;
           }
           else
           {
               return false;
           }
           return true;
       }
   }
}
